/*
 * 文  件   名： MemberAdapter.java
 * 版          权： Copyright GoPawPaw All Rights Reserved.
 * 描          述：[该类的简要描述]
 * 创  建   人： LiJinHua
 * 创建时间： 2012-5-26
 * 
 * 修   改  人：
 * 修改时间：
 * 修改内容：[修改内容]
 */
package com.longevityassistant.adapter;

import java.util.ArrayList;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import app.http.download.image.ImageLoadAdapter;

import com.longevityassistant.activity.R;
import com.longevityassistant.struct.Member;

/**
 * @author LiJinHua
 * @date 2012-5-26
 * @version [Android 1.0.0, 2012-5-26]
 * @description
 */
public class MemberAdapter extends ImageLoadAdapter{

	/**
	 * Log标签
	 */
	private static final String TAG = MemberAdapter.class.getSimpleName();
	
	private LayoutInflater mLayoutInflater;
	
	private ArrayList<Member> mMemberList;
	
	private Context context;
	public MemberAdapter(Context context,ArrayList<Member> memberList) {
		super();
		
		this.context = context;
		mLayoutInflater = LayoutInflater.from(context);
		this.mMemberList = memberList;
	}

	public void setData(ArrayList<Member> memberList){
		this.mMemberList = memberList;
	}
	
	@Override
	public int getCount() {
		if(mMemberList != null){
			return mMemberList.size();
		}
		return 0;
	}

	@Override
	public Member getItem(int position) {
		// TODO Auto-generated method stub
		if(mMemberList != null){
			return mMemberList.get(position);
		}
		return null;
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder holder = null;
		Member member=getItem(position);
		if(convertView==null || convertView.getTag()==null){
			holder = new ViewHolder();
			convertView = mLayoutInflater.inflate(R.layout.list_item_family, null);
			holder.icon =(ImageView) convertView.findViewById(R.id.imageview_icon);
			holder.name =(TextView) convertView.findViewById(R.id.textview_name);
			holder.valuse =(TextView) convertView.findViewById(R.id.textview_valuse);
			
			holder.level1 =(TextView) convertView.findViewById(R.id.textview_health_condition1);
			holder.level2 =(TextView) convertView.findViewById(R.id.textview_health_condition2);
			holder.level3 =(TextView) convertView.findViewById(R.id.textview_health_condition3);
			holder.level4 =(TextView) convertView.findViewById(R.id.textview_health_condition4);
			holder.level5 =(TextView) convertView.findViewById(R.id.textview_health_condition5);
			
			convertView.setTag(holder);
			
		}else{
			holder=(ViewHolder)convertView.getTag();
		}
		
//		holder.icon.setTag(member.urlIcon);
		
//		updateBitmapUI(holder.icon);
		holder.icon.setImageBitmap(BitmapFactory.decodeResource(context.getResources(), member.resIcon));
		holder.name.setText(""+member.name);
		holder.valuse.setText(""+member.valuse);
		holder.level1.setText(""+member.healthLevel1);
		holder.level2.setText(""+member.healthLevel2);
		holder.level3.setText(""+member.healthLevel3);
		holder.level4.setText(""+member.healthLevel4);
		holder.level5.setText(""+member.healthLevel5);
		
		return convertView;
	}
	
	
	class ViewHolder {
		
		private ImageView icon;
		private TextView name;
		private TextView valuse;
		private TextView level1;
		private TextView level2;
		private TextView level3;
		private TextView level4;
		private TextView level5;

	}


	


}

